<!DOCTYPE html>
<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>商品详情页</title>
    <meta name="keywords" content="商品详情页"/>
    <meta name="description" content="商品详情页"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1, maximum-scale=1,minimum-scale=1, user-scalable=no">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="format-detection" content="telephone=no"/>

    <meta name="viewport" content="width=device-width,viewport-fit=cover">
    <link rel="stylesheet" type="text/css" th:href="@{/shoppingApi/css/public.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/shoppingApi/css/swiper.min.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/shoppingApi/css/detail.css}">
    <link th:href="@{/shoppingApi/css/weui.min.css}" rel="stylesheet">
    <link th:href="@{/shoppingApi/css/jquery-weui.min.css}" rel="stylesheet">
    <style type="text/css" rel="stylesheet">
        .cf70029 {
            color: #323232;
        }

        .ft10 {
            font-size: 16px;
        }
    </style>
</head>
<body>
<div class="main detail">
    <div class="app-download"  th:if="${map!=null&&map.subscribe==null}">
        <a class="source" id="source">关注公众号购物体验更佳</a>
        <img class="close" th:src="@{/shoppingApi/images/app-close-btn.png}" alt="关闭">
    </div>
    <!--<div class="goback fixed-back" onclick="window.history.back()">-->
    <!--<h3>商品详情</h3>-->
    <!--</div>-->
    <!--<div class="goback static-back" onclick="window.history.back()"></div>-->

    <div class="main_con c323232 bgfff">
        <div class="detail_con rela">
            <div class="swiper-container">
                <div class="swiper-wrapper">
                    <input type="hidden" name="productId" id="productId" th:if="${map!=null}"
                           th:value="${map.productId}">
                    <div class="swiper-slide" style="padding-top:110%;position:relative;overflow:hidden;"
                         th:if="${map!=null}" th:each="guigeImg:${map.guige_img_list}">
                        <!--<img class="w100" th:src="@{/imgs/uploads/f7c901b5.jpg}">-->
                        <img class="w100 imgGroup" th:src="@{${'http://xlspic.ycsqd.com'+guigeImg}}"
                             style="width:100%;height:auto;position:absolute;top:0;left:0;">
                    </div>
                    <!--<div class="swiper-slide">-->
                    <!--<img class="w100" th:src="@{/shoppingApi/images/detail_pic.png}">-->
                    <!--</div>-->
                    <!--<div class="swiper-slide">-->
                    <!--<img class="w100" th:src="@{/shoppingApi/images/detail_pic.png}">-->
                    <!--</div>-->
                </div>
                <div class="swiper-pagination"></div>
            </div>
            <div class="pl15 pr15 pt10 pb10"><!--<label>~</label><label th:text="${map.maxProPrice}"></label>-->
                <p class="ft17 ft20 bold" style="color:#f70029"><span>￥</span><label class="minPrice"
                                                                                     th:text="${#numbers.formatDecimal(map.proPrice,1,2)}">66</label>
                </p>
                <p class="ft15 cf70029 mt10 mb10 rank-show-price" th:if="${map.productGuigePrice.activeSign==4 &&map.productGuigePrice.productId!=438}">
                    <span class="c323232 ">自用价:</span><span class="ft10">￥</span><label
                        th:text="${#numbers.formatDecimal(map.minyhPrice,1,2)}">12.00</label>
                </p>
                <input type="hidden" class="finace-cash" th:value="${map.productGuigePrice.yzDianzhu}"/>
                <p class="ft15 bold pro-title" th:if="${map!=null}"
                   th:text="${'【'+map.productGuigePrice.productName+'】'+map.productGuigePrice.productDesc}"></p>
            </div>
            <!--<img class="back abs" th:src="@{/shoppingApi/images/detail_back.png}">-->
        </div>
        <ul class="ft15 bgfff">
            <li>
                <p class="lititle">
                    <span class="tips-icon tips-icon1">省钱购</span>
                    <a href="javascript:openTips()" class="tips-layer-btn"><img
                            th:src="@{/shoppingApi/images/tips-icon3.png}"></a>
                </p>
                <div class="pl15 pr15 pb15 pt5">
                    <p th:if="${map.userNo!=null&&map.userNo.agent==1}">可使用<span
                            th:text="${map.config.finacename2}">兑换券</span>：￥<span class="cf70029"><label
                            th:text="${#numbers.formatDecimal(map.productGuigePrice.coupon,1,2)}"></label></span></p>
                    <p>可使用<span th:text="${map.config.finacename3}">折扣券</span><span
                            class="c969696 ft12">（最多）</span>：￥<span class="cf70029">
                        <label
                            th:text="${#numbers.formatDecimal(map.productGuigePrice.yzDianzhu,1,2)}"></label></span></p>

                    <p th:if="${map.productGuigePrice.productId!=438}">自用省<span class="c969696 ft12">（最多）</span>：￥<span class="cf70029"><label
                            th:text="${#numbers.formatDecimal(map.hyJSheng,1,2)}"></label></span></p>
                </div>
            </li>
            <li>
                <p class="lititle">
                    <span class="tips-icon tips-icon2">增值福利</span>
                    <a href="javascript:openTips()" class="tips-layer-btn"><img
                            th:src="@{/shoppingApi/images/tips-icon3.png}"></a>
                </p>
                <div class="pl15 pr15 pb15 pt5">
                    <!--<p>购买该商品可返<span class="c969696 ft12"> (最多) </span>￥<span class="cf70029"><label th:text="${#numbers.formatDecimal(map.productGuigePrice.proPrice*2,1,2)}">24</label></span><span th:text="${map.config.finacename3}">代金券</span></p>-->
                    <p>分享该商品即可获得<span class="c969696 ft12"> (至少) </span>￥<span class="cf70029">50.00</span><span
                            th:text="${map.config.finacename3}">代金券</span></p>
                </div>
            </li>
        </ul>
        <div class="line"></div>
        <div class="evaluation bgfff pl15 pr15">
            <p class="evaluation_title rela">
                <span>商品评价（10）</span>
                <span class="ft12 c969696 fr arrow mr10 look-all">查看全部</span>
            </p>
            <div class="flex pt15 pb15">
                <img class="userpic" th:src="@{/shoppingApi/images/userpic.png}">
                <p style="font-size:8px;line-height: 35px;margin-left: 10px" th:if="${map.userProductComment!=null}"
                   th:text="${map.userProductComment.name}">匿名</p>
                <p style="font-size:8px;line-height: 35px;margin-left: 10px" th:if="${map.userProductComment==null}">
                    匿名</p>
                <div class="it1 ml15">
                    <!--<p class="ft14 bold product-comment-user " th:if="${productComment!=null}" th:text="${productComment.userId}"></p>-->
                    <p style="font-size:8px;line-height: 35px;margin-left: 10px"
                       th:if="${map.userProductComment!=null&&map.userProductComment.cContent!=null}"
                       th:text="${map.userProductComment.cContent}"></p>
                    <p style="font-size:8px;line-height: 35px;margin-left: 10px" th:if="${map.userProductComment==null}"
                       th:text="${'暂无评论！'}"></p>
                    <input class="commentProductId" type="hidden" name="commentProductId"/>
                    <p class="ft10 c969696 mt5 mb10"></p>
                    <p class="ft14 pover2"></p>
                </div>
            </div>
        </div>
        <div class="line"></div>
        <div class="goods_pics">
            <p class="ft17 cf70029 ftc">商品详情</p>
            <!--<img class="w100 db" th:src="@{/shoppingApi/images/detail_pi2.png}">-->
            <img class="w100 db guige-zhutu" th:src="@{${'http://xlspic.ycsqd.com'+map.productGuigePrice.detailContent}}">
        </div>
        <div class="line"></div>
        <!--选择规格-->
        <div class="specifications c646464" style="display: none">
            <div class="specifications_con bgfff rela">
                <div class="flex pl15 pr15 pt20 pb20">
                <span class="img">
                    <!--规格主图-->
                    <!--<img class="w100" th:src="@{/shoppingApi/images/classimg1.png}">-->
                    <img class="w100 db guiges-zhutu" th:src="@{${'http://xlspic.ycsqd.com'+map.productGuigePrice.imgurl}}"/>
                </span>

                    <div class="flex flex-col ft17 ml15">
                        <p class="mt20 cf70029" style="color: #f70029;">
                            <span><span class="ft13"></span>￥<label class="proprice bold"
                                                                    th:text="${#numbers.formatDecimal(map.minProPrice,1,2)}">36.00</label></span><span
                                class="ml5 pro-Price">~￥<label class="bold"
                                                               th:text="${#numbers.formatDecimal(map.maxProPrice,1,2)}">26.8</label></span>
                        </p>
                        <!--<p class="ft14 cf70029" style="color: #f70029;">（赚￥<label class="fenxiangzhuan" th:text="${#numbers.formatDecimal(map.fenXiangZhuan,1,2)}">12.5~￥26.8</label>）</p>-->
                        <p class="specifi ft14 c323232">
                            <span class="default">请选择规格</span>
                            <span class="gauge"></span>
                            <span class="size ml5"></span>
                        </p>
                    </div>
                </div>
                <!--规格显示开始-->
                <div class="gauge gauges ft12 overflow c323232">
                    <p class="ft14 pl15">规格</p>
                    <ul>
                        <li class="pro-guiges" th:each="proGuigePrice:${map.proGuigePriceList}">
                            <span>
                                <label th:if="${proGuigePrice.proColor!='10'}" th:text="${proGuigePrice.guigeName}"></label>
                                <!--<label th:if="${productGuiGe==null}" th:text="${productGuiGe}"></label>-->
                            </span>
                            <input type="hidden" name="guigeId" class="guigeId" th:value="${proGuigePrice.guigeId}">
                        </li>
                    </ul>
                </div>
                <div class="gauge size ft12 overflow c323232" style="display: none">
                    <p class="ft14 pl15">尺码 /其他</p>
                    <ul>
                        <li>
                            <span><label></label></span>
                        </li>
                        </li>
                        <li>
                            <span>中号</span>
                        </li>
                        <li>
                            <span>小号</span>
                        </li>
                    </ul>
                </div>


                <!--规格显示结束-->
                <p class="pl15 pr15 overflow num">
                    <span class="fl ft15 changtext">数量</span>
                    <span class="fr ft17 changenum">
                    <span class="minus">-</span>
                    <span>
                        <input type="number" value="1">
                    </span>
                    <span class="add">+</span>
                </span>
                </p>
                <p class="tip mt15 ftc ft10" style="display: none">
                    <span>请选择产品规格</span>
                </p>
                <p class="bottom_btn overflow ftc">
                    <span class="addcart" style="background-color:#ff9900;color:#fff;" th:data="${map.isMoreAddress}">加入购物车</span>
                    <span class="buynow">立即购买</span>
                </p>
                <img class="close abs" th:src="@{/shoppingApi/images/close2.png}">
            </div>
        </div>

        <!--分享赚-->
        <!--<div class="sharediv">-->
        <!--<div class="sharediv_con">-->
        <!--<p>赚3.45</p>-->
        <!--<p class="ftc">1.只要你的好友</p>-->
        <!--</div>-->
        <!--</div>-->

        <div class="fixedBox50">
            <ul class="fixed-bottom bottom detail-navbar flex-ac flex-pc ftc bgfff">
                <li class="it1 index ft12">
                    <a th:href="@{/wap/productIndex}" class="db">
                        <span class="dib">
                            <img th:src="@{/shoppingApi/images/detail_index.png}">
                        </span>
                        <p>首页</p>
                    </a>
                </li>
                <li class="lineh">
                    <span class="lineh1"></span>
                </li>
                <li class="it1 like ft12 product-collect">
                    <span class="dib">
                        <img th:src="@{/shoppingApi/images/detail_like.png}">
                    </span>
                    <p>收藏</p>
                </li>
                <li class="lineh">
                    <span class="lineh1"></span>
                </li>
                <li class="it1 cart ft12">
                    <a th:href="@{/wap/getCartList}" class="db">
                        <span class="dib rela">
                            <img th:src="@{/shoppingApi/images/detail_cart.png}">
                            <span class="num abs car-product-count"></span>
                        </span>
                        <p>购物车</p>
                    </a>
                </li>
                <li class="it1 buy">
                    <span class="ft17 cfff">立即购买</span>
                </li>
                <li class="it1 sharebtn" id="sharebtn">
                    <p class="ft17 cfff" style="line-height: 49px;">分享赚</p>
                    <!--<p class="ft12 cfff">赚￥<label class="share-money" th:text="${#numbers.formatDecimal(map.fenXiangZhuan,1,2)}">0</label></p>-->
                </li>
            </ul>
        </div>
    </div>
</div>
<div id="tipsPopup" class="custom-dialog">
    <div class="custom-dialog__overlay"></div>
    <div class="custom-dialog__modal share-layer">
        <h3 class="custom-title"></h3>
        <div class="tips-wrap">
            <div class="tips-con">
                <h3 class="tips-title" th:text="${map.config.finacename2}">兑换卷</h3>
                <div class="tips-content">
                    <div class="tips-label">获取方式：</div>
                    <div class="tips-text"><p>通过官方活动不定期赠送</p></div>
                </div>
                <div class="tips-content">
                    <div class="tips-label">用途：</div>
                    <div class="tips-text"><p>可用于抵扣商品部分价格（有限额）</p></div>
                </div>
                <h3 class="tips-title" th:text="${map.config.finacename3}">折扣券</h3>
                <div class="tips-content">
                    <div class="tips-label">获取方式：</div>
                    <div class="tips-text">
                        <p>1.通过好友邀请注册（每邀请一位好友注册成功双方即可获得50元<span th:text="${map.config.finacename2}">折扣券</span>）</p>
                        <!--<p>2.购买商品后返<span th:text="${map.config.finacename3}">折扣券</span>（返实际支付金额的2倍，<span>不包含邮费</span>）</p>-->
                        <p>2.其他</p>
                    </div>
                </div>
                <div class="tips-content">
                    <div class="tips-label">用途：</div>
                    <div class="tips-text">
                        <p>可用于抵扣商品部分价格（有限额）</p>
                        <p><span>注意：不同身份的用户（游客、会员、店主）可抵扣的额度不同</span></p>
                    </div>
                </div>
            </div>
        </div>
        <a href="javascript:closetips()" class="custom-close"></a>
    </div>
</div>
<!--分享弹窗-->
<div id="sharePopup" class="weui-popup__container popup-bottom">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal share-layer">
        <p class="ft17 cff0000 mb10 mt10 text-center" th:if="${map.userCommission!=0}">赚<label class="getmoney"
                                                                                               th:text="${#numbers.formatDecimal(map.fenXiangZhuan,1,2)}"></label>
        </p>
        <!--未登录-->
        <p class="ft14 c323232 " style="padding: 15px 35px 10px 35px;"><span class="share-info"
                                                                             th:if="${map.userNo==null || map.userCommission==0}">1.注册获得代金券,为你购物省钱</span>
        </p>
        <p class="ft14 c323232" style="padding: 0 35px;"><span class="share-info"
                                                               th:if="${map.userNo==null || map.userCommission==0}">2.分享给朋友，双方都获得代金券</span>
        </p>
        <p class="ft14 c323232 pl15 pr15" th:if="${map.userCommission!=0}"><span class="share-info">只要你的好友通过你的链接购买此商品，你就能赚到至少</span><span
                class="cf70029 getmoney" th:text="${#numbers.formatDecimal(map.fenXiangZhuan,1,2)}"></span>元利润</p>


        <p class="flex mt20 mb20 flex-ac pl15 pr15">
            <span class="ml20 mr20 it1 lineh1"></span>
            <span class="ft14 c323232">分享到</span>
            <span class="ml20 mr20 it1 lineh1"></span>
        </p>
        <ul class="overflow ft14 c323232 ftc">
            <li id="shareMessage">
                <img class="wxhaoyou" th:src="@{/shoppingApi/images/share1.png}">
                <p class="mt10 ">微信好友</p>
            </li>
            <li id="shareTimeline">
                <img th:src="@{/shoppingApi/images/share2.png}">
                <p class="mt10">朋友圈</p>
            </li>
            <li id="shareImg">
                <img th:src="@{/shoppingApi/images/share4.png}">
                <p class="mt10">生成分享图</p>
            </li>
        </ul>
        <img class="close close-popup" th:src="@{/shoppingApi/images/close3.png}">
    </div>
</div>
<!--生成二维码-->
<div id="imageLayer" class="weui-gallery">
    <!--<img style="position:absolute;top:15%;left:15%;width:70%;" alt="">-->
    <div id="createImg" style="position:absolute;top:0;left:0;width:100%;height:100%;"></div>
    <!--<div class="weui-gallery__opr" id="saveImage" onclick="savePicture()">长按图片保存</div>-->
</div>
<input type="hidden" class="user-no-id" th:if="${map.userNo!=null}" th:value="${map.userNo.id}">
<input type="hidden" class="user-no-id" th:if="${map.userNo==null}" value="">
<input type="hidden" class="finace-name" th:value="${map.config.finacename3}">
<input type="hidden" class="finace-count" th:value="${map.config.giftDiscount}">
<input type="hidden" class="new-user-commission" th:value="${map.newUserCommission}">
<input type="hidden" class="user-commission" th:value="${map.userCommission}">
<input type="hidden" id="activeSign" th:value="${map.productGuigePrice.activeSign}">

<!--快速导航-->
<div class="mini-mask"></div>
<div class="mini-btn"></div>
<div class="mini-nav">
    <ul>
        <li><a href="/">
            <h5>首页</h5>
        </a></li>
        <li><a href="/wap/selectProductYJAndRjClassfy">
            <h5>分类</h5>
        </a></li>
        <li><a href="javascript:sharebtn()">
            <h5>分享</h5>
        </a></li>
        <li><a href="/wap/openUserCenter">
            <h5>个人中心</h5>
        </a></li>
        <li><a href="javascript:alert('敬请期待...')">
            <h5>店铺</h5>
        </a></li>
        <li><a href="/wap/getCartList">
            <h5>购物车</h5>
        </a></li>
        <li><a href="javascript:alert('敬请期待...')">
            <h5>联系客服</h5>
        </a></li>
    </ul>
</div>
<div id="mini-popup" class="weui-popup__container popup-bottom">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal share-layer">
        <p class="flex mt20 mb20 flex-ac pl15 pr15">
            <span class="ml20 mr20 it1 lineh1"></span>
            <span class="ft14 c323232">分享到</span>
            <span class="ml20 mr20 it1 lineh1"></span>
        </p>
        <ul class="overflow ft14 c323232 ftc">
            <li id="miniShareMessage">
                <img class="wxhaoyou" th:src="@{/shoppingApi/images/share1.png}">
                <p class="mt10 ">微信好友</p>
            </li>
            <li id="miniShareTimeline">
                <img th:src="@{/shoppingApi/images/share2.png}">
                <p class="mt10">朋友圈</p>
            </li>
        </ul>
        <img class="close close-popup" th:src="@{/shoppingApi/images/close3.png}">
    </div>
</div>
<!--/快速导航-->
<style>
    .weui-toast--text {
        top: 80%;
    }

    .mini-btn {
        z-index: 10;
    }
</style>
</body>
<script type="text/javascript" th:src="@{/shoppingApi/js/jquery-3.3.1.min.js}"></script>
<!--<script type="application/javascript" th:src="@{/shoppingApi/js/common.js}"></script>-->
<script type="application/javascript" th:src="@{/shoppingApi/js/swiper.min.js}"></script>
<script th:src="@{/shoppingApi/js/jquery-weui.min.js}"></script>
<!--<script type="text/javascript" th:src="@{/shoppingApi/js/H5Plus/common.js}"></script>-->
<script type="text/javascript" th:src="@{/shoppingApi/js/common.js}"></script>
<script type="text/javascript" th:src="@{/shoppingApi/js/plusShare.js}"></script>
<script th:src="@{/shoppingApi/js/mininav.js}"></script>
<script>

    $("#source").on('click', function () {
        $.modal({
            title: "",
            text: "<img src='/gzhewm.jpg' width='100%' />",
            buttons: [
                { text: "关闭", className: "default", onClick: function(){ console.log(3)} },
            ]
        });
    });

    var mySwiper = new Swiper('.swiper-container', {
        slidesPerView: 1,
        observer: true,
        observeParents: true,
        pagination: {
            el: '.swiper-pagination',
            type: 'fraction'
        }
    })
    /*返回上一页*/
    $(".back").on('click', function () {
        window.history.back(-1);
    })
    /*改变输入框的值*/
    $(".specifications_con .num input[type='number']").change(function () {
        var num = $(this).val()
        alert("数量：" + num)
    })

    /*数量加*/
    $(".specifications_con .num .changenum .add").on('click', function () {
        var newval = Number($(this).prev().find(":input[type='number']").val()) + 1;
        $(this).prev().find(":input[type='number']").val(newval);
    })

    /*数量减*/
    $(".specifications_con .num .changenum .minus").on('click', function () {
        if (Number($(this).next().find(":input[type='number']").val()) > 1) {
            var newval = Number($(this).next().find(":input[type='number']").val()) - 1;
            $(this).next().find(":input[type='number']").val(newval);
        }
    })

    /*选中规格*/
    var guigeId = 0;
    $(".pro-guiges").on('click', function () {
        guigeId = $(this).children('input').val();
        console.log("规格id=" + guigeId);
        $.ajax({
            type: "POST",
            url: "/wap/selectGuiGeById",
            data: {
                'guigeId': guigeId
            },

            success: function (result) {
                var imgGroup = result.imgGroups;
                var productGuiGe = result.productGuiGe;
                var productPrice = result.productPrice;
                var fenxiangZhuan = result.fenxiangZhuan;
                $.each(imgGroup, function (i) {
                    $('.imgGroup').attr("src", 'http://xlspic.ycsqd.com'+imgGroup[i]);//图组
                })
                $('.guiges-zhutu').attr("src", 'http://xlspic.ycsqd.com'+productGuiGe.imgurl);//规格主图
                $('.pro-Price').remove();
                $('.proprice').html(productPrice.proPrice.toFixed(2));
                $('.fenxiangzhuan').html(fenxiangZhuan.toFixed(2));
            }
        })
    })

    /*首页加入购物车*/
    $(".bottom_btn .addcart").on('click', function () {
        var isMoreAddress=parseInt($.trim($(this).attr('data')));
        //alert(isMoreAddress);
        if(isMoreAddress==1){
            $.toast("活动产品只能立即购买不能加入购物车！", "text");
            return;
        }
        var num = $(this).parents(".specifications_con").find(":input[type='number']").val();
        var productId = $('#productId').val();
        if ($.trim(guigeId) == 0) {
            // alert("请选择规格!");
            $.toast("请选择规格！", "text");
            return;
        }

        if($.trim(guigeId)==505){
            if(num>1){
                $.toast("当前产品单次限购数量1!",1000, function() {
                });
                return;
            }
        }

        //检测用户是否登录
        $.ajax({
            url: '/wap/verUserLogin',
            success: function (result) {
                console.log(result.userNo);
                if (!isLogin(result.userNo)) {
                    // var currentURL = window.location.href;
                    // window.location.href = '/wap/openLoginPwd?currentURL=' + currentURL;
                } else {
                    addCart(productId, guigeId, num);
                }
            }
        })
    })

    //加入购物车
    function addCart(productId, guigeId, num) {
        $.ajax({
            url: "/wap/addCart?productId=" + productId + "&guigeId=" + guigeId + "&productCount=" + num,
            dataType: "json",
            success: function (result) {
                if (result.data > 0) {
                    // window.location="/wap/getCartList";
                    $.toast("加入购物车成功！", "text");
                    window.location.reload();
                } else {
                    $.toast("添加购物车失败!", 'cancel');
                }
            }
        })
    }

    /*规格立即购买*/
    $(".bottom_btn .buynow").on('click', function () {
        var num = $(this).parents(".specifications_con").find(":input[type='number']").val();
        var productId = $.trim($('#productId').val());
        var activeSign = $.trim($('#activeSign').val());
        //选择规格
        if ($.trim(guigeId) == 0) {
            $.toast("请选择规格！", "text");
            return;
        }
        if($.trim(guigeId)==505){
            if(num>1){
                $.toast("当前产品单次限购数量1!",1000, function() {
                });
                return;
            }
        }
        //活动专区判断限购的数量及用户已购的数量
        if (activeSign == '7') {
           buyInfo=queryBuyCount(productId,guigeId,activeSign);
           if(buyInfo=='0'){
               $.toast("已达商品限购数量，不能再购买！");
               buyInfo='';
               return;
           }
           if(buyInfo=='1'){
               $.toast("已达个人限购数量，不能再购买！");
               buyInfo='';
               return;
           }
        }

        if (productId <= 0) {
            $.toast("请选择要购买的商品！", "text");
            return;
        } else {
            //检测用户是否登录
            $.ajax({
                url: '/wap/verUserLogin',
                async: false,
                success: function (result) {
                    if (!isLogin(result.userNo)) {
                        // var currentURL = window.location.href;
                        // window.location.href = '/wap/openLoginPwd?currentURL=' + currentURL;
                    } else {
                        //跳转到立即购买页面
                        window.location.href = "/wap/directAddOrder?productId=" + productId + "&guigeId=" + guigeId + "&productCount=" + num;
                    }
                }
            })

        }
    })
    /*规格页关闭*/
    $(".specifications_con .close").on('click', function () {
        $(".specifications").fadeToggle();
    })
    /*首页立即购买*/
    $(".fixedBox50 .buy").on('click', function () {
        $(".specifications").fadeToggle();

    })
    /*选择规格*/
    $(".specifications_con .gauges ul li").on('click', function () {
        if (!$(this).hasClass("active")) {
            $(this).siblings().removeClass("active");
            $(this).addClass("active");
            var text = $(this).find("span").text();
            $(".specifi span.default").text('');
            $(".specifi span.gauge").text(text);
            $(".tip").fadeOut();
        }
    })


    /*选择尺码*/
    $(".specifications_con .size ul li").on('click', function () {
        if (!$(this).hasClass("active")) {
            $(this).siblings().removeClass("active");
            $(this).addClass("active");
            var text = $(this).find("span").text();
            $(".specifi span.default").text('');
            $(".specifi span.size").text(text);
            $(".tip").fadeOut();
        }
    })

    $('.look-all').on('click', function () {
        alert("暂时无更多评论！");
        var productId = $('.commentProductId').val();
    })


    /*获取购物车总数*/
    function getCartListCount() {
        $.ajax({
            url: '/wap/getCartProCountByUserId',
            success: function (result) {
                console.log(result);
                if (result == 0) {
                    $('.car-product-count').html('0');
                } else {
                    $('.car-product-count').html(result);
                }
            }
        })
    }

    $(function () {
        getCartListCount();
    })

    // 分享赚
    var userNoId = '';
    var proId = '';
    var proTitle = '';
    var proImg = '';
    var qrImgUrl = '';
    $.toast.prototype.defaults.duration = 1000;
    $(function () {
        if (isApp()) {
            $('#saveImage').text('保存到手机相册');
        } else {
            $('.app-download').show();
            $('.app-download .close').click(function () {
                $('.app-download').hide();
            });
        }
        // if(navigator.userAgent.indexOf("Html5Plus") > -1){
        //     userNoId = plus.storage.getItem('userNoId') || '';
        // } else {
        //     userNoId = localStorage.getItem('userNoId') || '';
        // }
        userNoId = $('.user-no-id').val() || location.href.split('usernoid=')[1] || '';
        // 打开分享操作面板
        $('#sharebtn').on('click', function () {
            // if (!userNoId) {
            //     $.toast('登陆后才能分享！', 'text');
            //     return;
            // }
            proId = $('#productId').val();
            proImg = location.host + $('.imgGroup:first').attr('src');
            proTitle = $('.pro-title').text();
            // $('.getmoney').text($('.share-money').text());
            $('#sharePopup').popup();
        });
        // 分享朋友按钮
        $('#shareMessage').on('click', function () {
            if (!isLogin(userNoId, true, '登陆后才能分享')) return;
            if (isApp()) {
                // downloadEl.style.display = "none";//隐藏下载banner
                //分享内容，开发者可自定义
                var message = {
                    title: proTitle, //应用名字
                    content: "社区零售商店，优惠的价格购买满意的商品",
                    href: location.host + "/wap/getDetails?productId=" + proId + "&userNoId=" + userNoId, //分享出去后，点击跳转地址
                    thumbs: [proImg] //分享缩略图
                }
                //调起分享
                shareMessage(message, function (res) {
                    //分享回调函数
                    if (res) {
                        plus.nativeUI.toast("分享成功");
                    } else {
                        plus.nativeUI.toast("分享失败");
                    }
                    $.closePopup();
                })

            } else {
                // $.toast('请生成分享图', 'forbidden');
                qrImg();
            }
        });
        // 分享朋友圈按钮
        $('#shareTimeline').on('click', function () {
            if (!isLogin(userNoId, true, '登陆后才能分享')) return;
            if (isApp()) {
                // downloadEl.style.display = "none";//隐藏下载banner
                //分享内容，开发者可自定义
                var message = {
                    title: proTitle, //应用名字
                    content: proTitle,
                    href: location.host + "/wap/getDetails?productId=" + proId + "&userNoId=" + userNoId, //分享出去后，点击跳转地址
                    thumbs: [proImg] //分享缩略图
                }
                //调起分享
                shareTimeline(message, function (res) {
                    //分享回调函数
                    if (res) {
                        plus.nativeUI.toast("分享成功");
                    } else {
                        plus.nativeUI.toast("分享失败");
                    }
                    $.closePopup();
                })

            } else {
                // $.toast('请生成分享图', 'forbidden');
                qrImg();
            }
        });
        // 生成二位码按钮
        $('#shareImg').on('click', function () {
            if (!isLogin(userNoId, true, '登陆后才能生成分享图')) return;
            qrImg();
        });
        // 保存图片后关闭浮层
        // $('#saveImage').on('click', function (e) {
        //     if (isApp()) {
        //             plus.gallery.save(qrImgUrl, function () {
        //                 plus.nativeUI.toast("保存成功");
        //             }, function () {
        //                 plus.nativeUI.toast("保存失败");
        //             });
        //     }
        //     $('#imageLayer').hide();
        // });
        // 点击遮罩关闭浮层
        $('#imageLayer').on('click', function (e) {
            // var target = $(e.target);
            // if (target.is('#imageLayer')) {
            //     target.hide();
            // }
            $(this).hide();
        });
    });

    // 生成分享图片
    function qrImg() {
        $.showLoading('图片生成中');
        $.closePopup();
        $.ajax({
            type: 'get',
            url: '/wap/getEnCode?productId=' + proId,
            success: function (res) {
                if (res.ewmURL) {
                    console.log(res.ewmURL)
                    console.log(JSON.stringify(res.ewmURL))
                    if (res.loginInfo == 'unlogin') {
                        $.toast('请去个人中心登录！', 'cancel');
                        return;
                    }
                    $.hideLoading();
                    // 图片生成成功，打开浮层，关闭分享弹窗
                    imageLayer(res.ewmURL);
                } else {
                    setTimeout(function () {
                        $.hideLoading();
                        $.toast('图片生成失败', 'cancel');
                    }, 6000);
                }
            },
            error: function (err) {
                $.toast('图片生成失败', 'cancel');
                $.hideLoading();
            }
        });
    }

    // 图片浮层
    function imageLayer(img) {
        var layout = $('#imageLayer');
        qrImgUrl = location.host + img;
        // layout.find('img').attr('src', img);
        $('#createImg').css({
            background: 'url("' + img + '") center no-repeat rgba(0,0,0,0.8)',
            backgroundSize: 'contain'
        })
        layout.show();
        $.toast('请截图保存', 'text');
    }

    // 规则提示浮层
    function openTips(index) {
        $('#tipsPopup').addClass('custom-dialog--visible');
    }

    function closetips() {
        $('#tipsPopup').removeClass('custom-dialog--visible');
    }


    //收场商品
    $('.product-collect').on('click', function () {
        productCollect();
    })

    function productCollect() {
        var productId = $('#productId').val();
        var minPrice = $('.minPrice').html();
        $.ajax({
            async: false,
            url: '/wap/proAddCollect?productId=' + productId + "&productPrice=" + minPrice,
            success: function (res) {
                console.log(res);
                if (res.loginMsg != null) {
                    if (res.msg == '1') {
                        $.toast('已收藏！');
                    } else {
                        $.toast('收藏数据有误！', 'cancel');
                    }
                } else {
                    window.location.href = '/wap/openLoginPwd';
                }
            }
        })
    }

    //根据登录情况、等级显示商城价格
    showProPriceByLogin();

    function showProPriceByLogin() {
        var userNoId = $('.user-no-id').val();
        var newuserCommission = $('.new-user-commission').val();
        var userCommission = $('.user-commission').val();
        var finaceCash = $.trim(parseFloat($('.finace-cash').val()).toFixed(2));
        if (!userNoId) {
            $('.rank-show-price').hide();
            $('.share-money').html($('.finace-count').val());
        } else {
            if (userCommission <= newuserCommission) {
                $('.rank-show-price').html('可用代金券:<span class="ft15 cf70029">￥</span><span class="cf70029 ft17 bold">' + finaceCash + '</span>');
                $('.share-money').html($('.finace-count').val());
            }
        }
    }

    // app诊断
    function isApp() {
        return navigator.userAgent.indexOf("Html5Plus") > -1;
    }

    var r = null;
    // 扩展API加载完毕，现在可以正常调用扩展API
    if (window.plus) {
        onPlusReady();
    } else {
        document.addEventListener("plusready", onPlusReady, false);
    }

    function onPlusReady() {
        r = plus.gallery
    }

    // 保存图片到相册中
    function savePicture() {
        // plus.gallery.save( "_doc/a.jpg", function () {
        //     alert( "保存图片到相册成功" );
        // } );
        if (isApp()) {
            // var src = $('#imageLayer').find('img').attr('src');
            // plus.gallery.save('http://www.ycsqd.com/1552190271520.jpg', function () {
            r.save(qrImgUrl, function () {
                plus.nativeUI.toast("保存成功");
            }, function () {
                plus.nativeUI.toast("保存失败" + qrImgUrl);
            });
        }
        $('#imageLayer').hide();
    }
var buyInfo='';
function queryBuyCount(productId,guigeId,activeSign) {
    $.ajax({
        async:false,
        url: '/wap/getPayOrderProductCount?productId=' + productId + '&guigeId=' + guigeId + '&activeSign=' + activeSign,
        success: function (res) {
            if(res.msg=="0"){
                buyInfo='0';
            }else if(res.msg=='1'){
                buyInfo='1';
            }
        }
    })
    return buyInfo;
}

</script>
</html>

